using CfgTable;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using NetProtocol.POD;
using System.Collections.Generic;

namespace IQIGame.Onigao.GamePlay
{
    public class UD_QuestGet : UIBaseData
    {
        public int cid { get; private set; }
        public List<ItemShowData> rewards { get; private set; }

        public CfgQuest cfgData => TableCenter.quest.Get(cid);

        public UD_QuestGet Sync(int cid, List<ItemShowPOD> awards)
        {
            this.cid = cid;
            List<ItemShowData> listAwards = ListPool<ItemShowData>.Get();
            ItemModule.Instance.ConvertListFrom(awards, listAwards);
            this.rewards = listAwards;
            return this;
        }

        public void Clear()
        {
            this.cid = 0;
            var list = this.rewards;
            this.rewards = null;

            if (list.Count > 0)
            {
                foreach (var item in list)
                {
                    item.Put2Pool();
                }
                ListPool<ItemShowData>.Put(list);
            }
        }

        #region 对象池
        public override void OnReset()
        {
            this.Clear();
        }

        static public UD_QuestGet NewFromPool()
        {
            return ClassPool<UD_QuestGet>.Get();
        }
        #endregion
    }
}
